#include "StdAfx.h"
#include "TraceCollection.h"


TraceCollection::TraceCollection(void)
{
}


TraceCollection::~TraceCollection(void)
{
}

void TraceCollection::AddMessage(const LogMessage& message)
{
	if (message.function == FunHeapAlloc)
	{
		m_memtraceMap.insert(make_pair(message.memAlloc, message));
	}
	else if (message.function == FunHeapFree){
		m_memtraceMap.erase(message.memAlloc);
	}
}

const TraceCollection::MessageMap& TraceCollection::GetMessageMap() const
{
	return m_memtraceMap;
}

const TraceCollection::GroupedMessageMap TraceCollection::GetGroupedMessageMap()
{
	GroupedMessageMap groupedMessageMap;
	auto it = m_memtraceMap.begin(); 
	while(it != m_memtraceMap.end()){
		const LogMessage &message = it->second;
		groupedMessageMap[message.callStack].push_back(message);
		++it;
	}
	return groupedMessageMap;
}